import {UmsparentListRes, UserType} from '@/type/ums'
import {ModalFormTreeOption} from '@/type/ModalFormType'

export const info:UserType = JSON.parse(sessionStorage.getItem('info')!)

export function processTreeNode(node:UmsparentListRes):ModalFormTreeOption {
  const modalFormTreeOption:ModalFormTreeOption = {
    label: node.menu_name,
    key: node.id.toString(),
  };
  if (node.children && node.children.length > 0) {
    modalFormTreeOption!.children = node.children.map(processTreeNode);
  }
  return modalFormTreeOption;
}

export function treeNode<T> (node: T, option:ModalFormTreeOption):ModalFormTreeOption {
  // debugger
  const options = JSON.parse(JSON.stringify(option))
  const modelForm:ModalFormTreeOption = {
    label: node[option.label],
    key: node[option.key]
  }
  if (node.children && node.children.length > 0) {
    modelForm!.children = node.children.map((item) => treeNode(item, options))
  }
  return modelForm
}
